<template>
  <div class="login-container">
     <div class="slider">
         <div :class="active === 1 ? 'form' :'form hidden'">
             <div class="title">恭迎金主归来</div>
             <div class="subtitle">登录你的账户</div>
             <form :model ="admin" class="formcss">
                 <div class="inputf">
                     <input v-model="admin.username" type="text" placeholder="用户名" />
                     <span class="label">用户名</span>
                 </div>
                 <div class="inputf">
                     <input v-model="admin.password" type="text" placeholder="密码" />
                     <span class="label">密码</span>
                 </div>
             </form>
             <button @click="login()">登录</button>
         </div>
         <div :class="active === 2 ? 'form' : 'form hidden'">
             <div class="title">感恩金主入驻</div>
             <div class="subtitle">注册你的账户</div>
             <div class="inputf">
                 <input type="text" placeholder="用户名" v-model="userinfo.username" />
                 <span class="label">用户名</span>
             </div>
             <div class="inputf">
                 <input type="text" placeholder="邮箱" v-model="userinfo.email" />
                 <span class="label">邮箱</span>
             </div>
             <div class="inputf" >
                 <input type="text" placeholder="联系方式"  v-model="userinfo.phone" />
                 <span class="label">联系方式</span>
             </div>
             <div class="inputf">
                 <input type="text" placeholder="密码" v-model="userinfo.password" />
                 <span class="label">密码</span>
             </div>
             <button @click="log()">注册</button>
         </div>
         <div :class="active === 1? 'card' : 'card active'">
             <div class="head">
                 <div class="name">迈迪科<span>医疗器械</span></div>
             </div>
             <div class="desc">我们专注为各级企业及家庭需求提供最精湛的器械，为您的健康安全保驾护航。我们会提供最周到的服务与介绍，让您挑选到最适合您需求的器械。我们会不断更新技术，推出新产品持续为您服务，给您不一样的医疗体验！对我们感兴趣的话不妨进来看看！</div>
             <div class="btn">
                 {{ active === 1 ? '新用户？' : '已有帐号？'}}
                 <button @click="active = (active === 1) ? 2 : 1">
                     {{ active === 1 ? '去注册' : '去登陆'}}
                 </button>
             </div>
         </div>
     </div>
  </div>
</template>

<script setup>
import {ref} from "vue";

const active = ref(1)
</script>

<style lang="scss">

.formcss{
    width: 92%;
}
.login-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: url("../assets/back-7.png") no-repeat center center;
    background-size: cover;

    .slider {
        position: relative;
        display: flex;
        justify-content: center;
        align-items: center;
        .form {
            width: 400px;
            height: 500px;
            background: rgba(30,60,100,0.75);
            backdrop-filter: blur(16px) saturate(0);
            border-radius: 10px;
            border: 1px solid rgba(255,255,255,0.15);
            padding: 40px 60px;
            box-shadow: rgba(50,50,93,0.25) 50px 50px 100px -20px,
            rgba(0,0,0,0.5) 30px 30px 60px -30px,
            rgba(212,217,222,0.25) 2px -2px 6px 0px inset;
            display: flex;
            justify-content: center;
            flex-direction: column;
            align-items: flex-start;
            margin: 0 10px;
            z-index: 3;
            transition: 0.5s ease-in-out;

            &.hidden {
                height: 395px;
                box-shadow: none;
                z-index: 1;
            }

            .title {
                font-family: 华文行楷;
                font-size: 28px;
                color: rgb(246,240,255);
                letter-spacing: 1px;
                font-weight: 300;
            }
            .subtitle {
                font-family: 华文行楷;
                font-size: 20px;
                color: rgb(246,240,255);
                letter-spacing: 1px;
                margin-bottom: 35px;
            }
            .inputf {
                width: 100%;
                position: relative;
                margin-bottom: 35px;
                input {
                    width: 100%;
                    height: 35px;
                    border: none;
                    outline: 1.5px solid rgb(200,240,255);
                    background: transparent;
                    border-radius: 8px;
                    font-size: 12px;
                    padding: 0 15px;
                    color: rgb(246,240,255);
                    &::placeholder {
                        color: rgb(175,180,190);
                    }
                    &:focus {
                        outline: 1.5px solid rgb(224,249,240);
                        &::placeholder {
                            opacity: 0;
                        }
                        & + .label {
                            opacity: 1;
                            top: -20px;
                        }
                    }
                    &:not(:placeholder-shown) + .label {
                        bopacity: 1;
                        top: -20px;
                    }
                }
                .label {
                    position: absolute;
                    top: 0;
                    left: 0;
                    color: rgb(246,249,255);
                    font-size: 11px;
                    font-weight: bold;
                    transition: 0.25s ease-out;
                    opacity: 0;
                }
            }
            button {
                width: 100%;
                height: 35px;
                background: rgb(26,217,127);
                color: #ffffff;
                border: none;
                outline: none;
                border-radius: 5px;
                font-weight: bold;
                font-size: 12px;
                cursor: pointer;
            }
        }
        .card {
            position: absolute;
            right: 0;
            top: 50%;
            transform: translate(0, -50%);
            width: 472px;
            height: 400px;
            background: url("../assets/mdk-card.png") white;
            background-size: contain;
            padding: 40px;
            border-radius: 0 10px 10px 0;
            transition: 0.5s ease-in-out;
            z-index: 2;
            &.active {
                right: calc(100% - 552px );
                border-radius: 10px 0 0 10px;
            }
            .head {
                font-size: 50px;
                font-family: 华文新魏;
                color: rgb(30,30,127);
                font-weight: bolder;
                margin-bottom: 35px;
                .name {
                    font-weight: 300;
                    span {
                        color: rgb(30,160,127);
                        font-weight: bold;
                    }
                }
            }
            .desc {
                font-size: 24px;
                font-family: 华文行楷, sans-serif;
                text-align: justify;
                margin-bottom: 45px;

            }
            .btn {
                font-size: 15px;
                button {
                    background: rgb(36,100,127);
                    font-size: 14px;
                    color: white;
                    padding: 5px 15px;
                    border: none;
                    outline: none;
                    border-radius: 5px;
                    cursor: pointer;
                    margin-left: 10px;
                }
            }
        }
    }

}
</style>



<script>

import axios from "axios";

export default {
    name : "Login",
    data() {
        return {
            admin :{},
            userinfo:{
                username:"",
                password:"",
                email:"",
                phone:"",
            }
        }
    },
    created() {

    },
    methods :{
        login() {
            let result = ""
            console.log(this.admin)
            axios.post("http://localhost:9091/user/login",this.admin).then(res=>{
                console.log(res)
                result = res.data.data
                if(result == "no"){
                    this.$message({
                        message: '登录失败！',
                        type: 'error'
                    });
                    return;

                }
                else if(result == "admin"){
                    this.$store.commit('setLoginStates',true);
                    this.$message({
                        message: '登录成功！',
                        type: 'success'
                    });
                    this.$router.push({ name: 'back' });
                }else {
                    this.$store.commit('setLoginStates',true);
                    this.$message({
                        message: '登录成功！',
                        type: 'success'
                    });
                    this.$router.push({ name: 'home1' });
                }

            })

            // console.log(this.admin)
            // axios.post("http://localhost:9090/admin/login",this.admin).then(res=>{
            //     console.log(res)
            // })
            // request.post("/login", this.admin).then(res => {
            //     console.log(this.admin);
            //     // if (res.code === '0') {
            //     //     this.$message({
            //     //         message: '登录成功！',
            //     //         type: 'success'
            //     //     });
            //     //     this.$router.push("/");
            //     // } else {
            //     //     this.$message({
            //     //         message: res.msg,
            //     //         type: 'error'
            //     //     });
            //     // }
            //
            // })
        },
        log(){
            console.log(this.userinfo)
            axios.post("http://localhost:9091/user/register",this.userinfo).then(res=>{
                console.log(res)
            })
        }
    }
}
</script>